class MyCircularQueue {
    private int[] elem;//数组用来存放队列的元素
    private int front;//对头
    private int rear;//队尾

    public MyCircularQueue(int k) {
         this.elem = new int[k+1];//初始化k+1个空间,多余一个空间空出来用于判断是否满
    }
    //入队
    public boolean enQueue(int value) {
         if(isFull()){
             return false;
         }
         this.elem[rear] = value;
         this.rear = (this.rear+1)%this.elem.length;
         return true;
    }
    //出队
    public boolean deQueue() {
       if(isEmpty()){
           return false;
       }
       this.front = (this.front+1)%this.elem.length;
       return true;
    }
    
    public int Front() {
        if(isEmpty()){
            return -1;
        }
        return this.elem[front];
    }
    
    public int Rear() {
        if(isEmpty()){
            return -1;
        }
        int index = (this.rear==0)?(this.elem.length-1):rear-1;
        return this.elem[index];
    }
    
    public boolean isEmpty() {
         return front==rear;
    }
    
    public boolean isFull() {
          if((this.rear+1)%this.elem.length==front){
              return true;
          }
          return false;
    }
}